<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" > 

<html>
<head>
<base href="<%=basePath%>">
<title>新增疾病</title>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap.css" type="text/css"/>
<link rel="stylesheet" href="./js/metisMenu/metisMenu.min.css">
<link rel="stylesheet" href="./css/sb-admin/sb-admin-2.css">
<link rel="stylesheet" href="./css/base.css">
<link rel="stylesheet" href="./css/illness.css">
<link rel="stylesheet" href="./js/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="./js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="./js/bootstrap-multiselect/bootstrap-multiselect.css" type="text/css"/>
<link rel="stylesheet" href="./js/bootstrap-3.3.5-dist/css/bootstrap-datetimepicker.css">

<script type="text/javascript" src="./js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="./js/bootstrap-3.3.5-dist/js/bootstrap.js"></script>
<script type="text/javascript" src="./js/metisMenu/metisMenu.js"></script>
<script type="text/javascript" src="./js/common.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-all.min.js"></script>
<script src="./js/bootstrap-table/bootstrap-table-zh-CN.min.js"></script>
<script src="./js/bootstrap-multiselect/bootstrap-multiselect.js"></script>
<script src="./js/bootstrap-jquery-plugin/jquery.bootstrap.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.js"></script>
<script src="./js/bootstrap-3.3.5-dist/js/bootstrap-datetimepicker.zh-CN.js"></script>
<script src="./js/ajaxfileupload.js"></script>

</head>
<body>
	<jsp:include page="../template/head.jsp" />
	<jsp:include page="../template/leftnav.jsp" />
	<div id="page-wrapper">
		<div class="wrapper">
			<h1><a href="./jsp/illness/illness.jsp">疾病列表</a></h1><h3> <span> > </span> 新增疾病</h3>
		</div>
		<div class="bHead">
			<ul class="list-inline">	
				<li>
					<label>疾病名称：</label>
					<input class="form-control" style="display:-webkit-inline-box;width: inherit;" id="illName" placeholder="请输入疾病名称" onkeyup="filters(this)" onchange="filters(this)"/>
				</li>
			</ul>
		</div>	
		<div class="i-detail i-detail-info">
			<h3>基本信息</h3>
						<div class="list-inline" style="margin:5px">
				<label>多发性别：</label>
				<select id="specialCrowdSel">
				    <option value="0" selected>男</option>
				    <option value="1" selected>女</option>
				    <option value="2" selected>全部</option>
				</select>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>疾病年龄：</label>
	        	<select id="ssdiseaseAgeSel" multiple="multiple">
				    	<option value="1" selected>0-30天</option>
					    <option value="2" selected>31天-3岁</option>
					    <option value="3" selected>4-8岁</option>
					    <option value="4" selected>9-14岁</option>
					    <option value="5" selected>15-35岁</option>
					    <option value="6" selected>36-64岁</option>
					    <option value="7" selected>65岁以上</option>
				</select>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>一级科目：</label>
				<input class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="levelOneSubject" placeholder="请输入一级科目" onkeyup="filters(this)" onchange="filters(this)"/>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>二级科目：</label>
				<input class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="levelTwoSubject" placeholder="请输入二级科目" onkeyup="filters(this)" onchange="filters(this)"/>
			</div>
<!-- 			<div class="list-inline" style="margin:5px">
				<label>是否受伤：</label>
	            <select id="isInjuredSel">
				    <option value="1" selected>是</option>
				    <option value="0" selected>否</option>
				</select>
			</div> -->

			<div class="list-inline" style="margin:5px">
				<label >发生时间：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="duration" placeholder="请输入发病时间" ></textarea>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>辅助检查：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="examNames" placeholder="请输入辅助检查" ></textarea>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>病情病因：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="pathogen" placeholder="请输入病情病因" ></textarea>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>诊疗方案：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="scheme" placeholder="请输入诊疗方案" ></textarea>
			</div>
			<div class="list-inline" style="margin:5px">
				<label>疾病用药：</label>
				<textarea class="form-control" style="width:85% !important; display:-webkit-inline-box;width: inherit;" id="medicines" placeholder="请输入该疾病所用药物" ></textarea>
			</div>

		</div>
		
		<div class="panel bs-panel-primary" style="height: auto !important" >
			<div class="panel-heading">症状名称:
				<span class="btn detail—btn" onclick="addSymptomDiv()">添加</span>
			</div>
			<div class="list-inline" >
				<div style="margin:5px 5px 5px 15px;">
				<div style="margin:5px 5px 5px 15px;">
				</div>
				<div id="ii"></div>
			</div>
		</div>
		
<!-- 		<div class="panel bs-panel-primary" style="height: auto !important" >
			<div class="panel-heading">部位名称:
				<span class="btn detail—btn" onclick="addpartsDiv()">添加</span>
			</div>
			<div class="list-inline" >
				<div id="pp"></div>
			</div>
		</div> -->
		
		<div style="text-align: center;padding: 40px 0;">
			<button onclick="addIll()" class="btn btn-primary">提交</button>
			<a href="./jsp/illness/illness.jsp" class="btn btn-primary">取消</a>
		</div>
		
</body>
<script type="text/javascript">
	var symptomDiv = 0;
	var partsDiv = 0;
	var imgurls = [];
	$(function () {
		 
	 	 $('#ssdiseaseAgeSel').multiselect({
		 	includeSelectAllOption: true,
		 	selectAllText: "全部年龄",
		 	allSelectedText:"全选",
		 	nonSelectedText:"无",
		 	buttonWidth: '150px'
		 });
		 
	 	 $('#specialCrowdSel').multiselect({
		 	includeSelectAllOption: true,
		 	buttonWidth: '150px'
		 });
		 
	});
	
	function ajaxFileUpload(symptomDiv){
	    $.ajaxFileUpload({
	            url: "./imageOpt/photoUpload",
	            secureuri: false, 
	            fileElementId: 'file'+symptomDiv, 
	            dataType: 'json', 
	            success: function (data, status){
	            	if(data.resultCode==0){
						var img = {
							id : symptomDiv,
							url : data.content
						};
	            		imgurls.push(img);
	            	}
					$.messager.popup(data.msg);
	            },
	            error: function (data, status, e){
	                alert(e);
	            }
	        }
	    )
	    return false;
	}
	
	function addSymptomDiv(){
		symptomDiv++;
		var html += '<div >';
			html += '<h5 style="color: #fff;background-color: #939bf3; padding: 5px;border-radius: 4px;">症状'+symptomDiv+':</h5>';
			html +='<span style="color: #37bd9c;" class="glyphicon glyphicon-plus icon-plus" aria-hidden="true" ></span>';
			html +='<lable style="margin-left: 5px;">症状：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;" id="symptom'+symptomDiv+'" '+'placeholder="请输入症状" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<lable style="margin-left: 5px;">部位：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;" id="parts'+symptomDiv+'" '+'placeholder="请输入症状" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<lable style="margin-left: 5px;">程度：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="degree'+symptomDiv+'" '+'placeholder="程度" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<lable style="margin-left: 5px;">性质：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="nature'+symptomDiv+'" '+'placeholder="性质" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<br>';
			html +='<span style="color: #37bd9c;opacity:0;" class="glyphicon glyphicon-plus icon-plus" aria-hidden="true" ></span>';
			html +='<lable style="margin-left: 5px;">次数：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="times'+symptomDiv+'" '+'placeholder="次数" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<lable style="margin-left: 5px;">用药：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="medicine'+symptomDiv+'" '+'placeholder="用药" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<lable style="margin-left: 5px;">值下限：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="sdown'+symptomDiv+'" '+'placeholder="值下限" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<lable style="margin-left: 5px;">值上行：</lable>';
			html +='<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="sup'+symptomDiv+'" '+'placeholder="值上限" onkeyup="filters(this)" onchange="filters(this)"/>';
			html +='<br>';
			html +='<span style="color: #37bd9c;opacity:0;" class="glyphicon glyphicon-plus icon-plus" aria-hidden="true" ></span>';
			html +='<lable style="margin-left: 5px;">描述：</lable>';
			html +='<textarea class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="description'+symptomDiv+'" '+'placeholder="描述" onkeyup="filters(this)" onchange="filters(this)"></textarea>';
/* 			'<lable>范围：</lable>'+
			'<input class="form-control" style="display:-webkit-inline-box;width: inherit;" id="type'+symptomDiv+'" placeholder="是否为全身病症，是或否" onkeyup="filters(this)" onchange="filters(this)"/>'+	 */		    
			html +='<input type="file" id="file'+symptomDiv+'" name="file" style="width:30%;display:inline-block;margin-left:5px"/><input type="button" value="上传照片" onclick="ajaxFileUpload('+symptomDiv+')"/>';
			html +='</div>';
		var div =document.createElement("div");
        div.innerHTML=html;
   		document.getElementById("ii").appendChild(div);
	}
	
	function addpartsDiv(){
		partsDiv++;
		var html = '<div style="margin:5px 5px 5px 15px;">'+
			'<span style="color: #37bd9c;" class="glyphicon glyphicon-plus icon-plus" aria-hidden="true" ></span>'+
			'<input class="form-control" style="display:-webkit-inline-box;width: inherit;margin:3px;" id="parts'+partsDiv+'" '+'placeholder="部位" onkeyup="filters(this)" onchange="filters(this)"/>'+
			'</div>';
		var div =document.createElement("div");
        div.innerHTML=html;
   		document.getElementById("pp").appendChild(div);
	}
	
	function ping(symptom,degree,nature,times,medicine,type,sdown,sup,imgurl,parts,description){
		var sobj = {
			symptom :symptom,
			degree : degree,
			nature : nature,
			times : times,
			medicine :medicine,
			type : type,
			sdown : sdown,
			sup :sup,
			imgurl :imgurl,
			parts : parts,
			description : description
		};
		return sobj;
	}
	
	function addIll(){
		var illName = $("#illName").val();
		var levelOneSubject = $("#levelOneSubject").val();
		var levelTwoSubject = $("#levelTwoSubject").val();
    	var duration = $("#duration").val();
   		var examNames = $("#examNames").val();
   		var sex = $("#specialCrowdSel").val();
   		var pathogen = $("#pathogen").val();
   		var scheme = $("#scheme").val();
   		var medicines = $("#medicines").val();
        var age = $("#ssdiseaseAgeSel").val();
        var ages = [];
        var aobj;
        for(var i=0;i<=age.length-1;i++){
        console.log(age[i]);
        	aobj={
				ageOption : age[i]
			};
			ages.push(aobj);
        	
        }
/* 		var parts = [];
		var pobj;
		for(var i=1 ;i<=partsDiv;i++){
			
			if($("#parts"+i+"").val() && $("#parts"+i+"").val()!=null){
				pobj={
					part : $("#parts"+i+"").val()
				};
				parts.push(pobj);
			}
		} */

		
				
		var symptoms=[];
		for(var i=1;i<=symptomDiv;i++){
			if($("#symptom"+i+"").val() && $("#symptom"+i+"").val()!=null){
				var s = $("#symptom"+i+"").val();
				var d = $("#degree"+i+"").val();
				var n = $("#nature"+i+"").val();
				var t = $("#times"+i+"").val();
				var m = $("#medicine"+i+"").val();
				var type = $("#type"+i+"").val();
				var sdown = $("#sdown"+i+"").val();
				var sup = $("#sup"+i+"").val();
				var parts = $("#parts"+i+"").val();
				var description = $("#description"+i+"").val();
				if($("#type"+i+"").val()=="是"){
					type = 1;
				}else{
					type = 0;
				}
				var imgurl;
				for(var j=0;j<imgurls.length;j++){
					if(imgurls[j].id==i){
						imgurl = imgurls[j].url;
					}
				}
				symptoms.push(ping(s,d,n,t,m,type,sdown,sup,imgurl,parts,description));
			}
		}
		
		var obj = {
         		illness:illName,
				duration:duration,
				sex:sex,
				levelOneSubject:levelOneSubject,
				levelTwoSubject:levelTwoSubject,
				assistantExam:examNames,
				pathogen:pathogen,
				scheme:scheme,
				medicine:medicines,
           		symptoms:symptoms,
           		ages : ages
           };
		
		$.ajax({
           url: "./adminIllness/addIll",
           data: JSON.stringify(obj),
           type: "POST",
           dataType: 'json',
           contentType:"application/json",
           success: function (ret) {
           		if(ret.resultCode==0){
					window.location.href="./jsp/illness/illness.jsp";
              	}
           }
       });
	}
</script>
</html>
